Changes to render full information on alarm tree non-leaf nodes. Also… - #3910
Conversation
… code cleanup/reduction
|
@shroffk, any objections to merging this? |
| protected static Set<AlarmClientLeaf> getLeafItems(List<AlarmTreeItem<?>> items){ | ||
| Set<AlarmClientLeaf> leaves = new HashSet<>(); | ||
| items.forEach(item -> leaves.addAll(getLeafItems(item))); | ||
| return leaves; |
There was a problem hiding this comment.
I think this results in much copying and allocation on the heap: every leaf is copied once per layer from the leaf in question to the root.
I think this and the next method (which takes as argument a AlarmTreeItem<?> root) can be combined into a method that takes only a final AlarmTreeItem<?> root as its argument, plus a helper method for traversing the tree, along the following lines:
protected static Set<AlarmClientLeaf> getLeafItems(final AlarmTreeItem<?> root) {
return streamLeafItems(root).collect(Collectors.toSet());
}
private static Stream<AlarmClientLeaf> streamLeafItems(final AlarmTreeItem<?> alarmTreeItem){
if (alarmTreeItem instanceof AlarmClientLeaf alarmClientLeaf){
return Stream.of(alarmClientLeaf);
}
else {
return alarmTreeItem.getChildren().stream().flatMap(child -> streamLeafItems(child));
}
}
There was a problem hiding this comment.
every leaf is copied once
What does "copied" here mean? No new AlarmClientLeaf objects are created.
But maybe you mean new Set objects are created and AlarmClientLeaf references are copied over?
There was a problem hiding this comment.
You are correct: "copying" was inaccurate. I should have written "re-insertion" instead: a reference to every leaf is inserted into a HashSet once per layer from the leaf in question to the root, and each re-insertion (1) hashes the element and (2) allocates a node for the hash set.
|
|
||
| protected static Set<AlarmClientLeaf> getLeafItems(final AlarmTreeItem<?> root){ | ||
| Set<AlarmClientLeaf> leaves = new HashSet<>(); | ||
| if(root instanceof AlarmClientLeaf){ |
There was a problem hiding this comment.
The cast can be made type safe:
if(root instanceof AlarmClientLeaf alarmClientLeaf) {
…selection in alarm tree view
|



This is a follow up on #3880, aiming at reducing code complexity while also updating the alarm tree view to provide more information on non-leaf nodes.
Suggestion is to show full information on non-leaf nodes:
Screenshots below.
The view may become a bit cluttered as shown in the first example. However, the second example should probably reflect a more realistic scenario.
Testing:
Documentation: